import React, { Component } from 'react'

export default class Form1 extends Component {
  username = React.createRef();
  password = React.createRef();
  
  render() {
    return (
      <div>
        <h2>登录</h2>
        用户名: <input ref={this.username} type="text" /><br></br>
        密码: <input ref={this.password} type="password" /><br  />
        <button onClick={this.login}>登录</button>
      </div>
    )
  }

  //登录按钮的点击回调
  login = () => {
    let user = this.username.current.value;
    let pass = this.password.current.value;
    //输出
    console.log(`用户名为 ${user} 密码为 ${pass}`);
  }
}
